var Utils = require('../../../../utils/util.js');
let __test_account__, __test_psword__;
let disp = require("../../../../utils/broadcast");
let runAnimation = true
var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    is_vip: false,
    isLoading: !0,
    startPoint: [0, 0],
    change: 1,
    bigMask: true,
    questiontabs: 0,
    allserve: false,
    shanchanglist: ["全部(550)", "气胸(16)", "肺癌(18)", "胸腔积液(5)", "肋骨骨折(4)", "心包积液(2)", "多汗症(1)"],
    pop_key: false,
    tabu_index: 1,
    ctab_scroll: [],
    ctab_scroll_index: 0,
    video: false,
    pop_time1: '',
    pop_time2: '',
    userInfo: {},
    fuwu:false,
    hasUserInfo: false,
    // 主治擅长
    adepd: false,
    collect: false,
    parise: false,
    scrollleft: 0,
    username: "徐三",
    inquiry: "",
    ifqianyue: 0,
    modelBoo: false,
    text: '签约医生',
    shareState: false,
    show_text: false,
    authStateBoo: true,
    consultation_index: 0,
    userfamily:[],
    consultation_state: false
  },
  gohospital: function (e) {
    var hid = e.currentTarget.dataset.hid;
    wx.navigateTo({
      url: '/hyb_yl/mycenter/pages/mechanism/mechanism?hid=' + hid,
    })
  },
  godoctor_info: function () {
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/doctor_info/doctor_info?zid=' + this.data.zid,
    })
  },
  suifang:function(){
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/huanzhe/pages/private_services/private_services?zid='+that.data.zid,
    })
  },
  allanswer: function (e) {
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/alladept/alladept?zid=' + this.data.zid,
    })
  },
  doctoritems:function(e){
    var that = this;
    var zid = that.data.zid;
    var ifqianyue = e.currentTarget.dataset.ifqianyue;
    var fuwu = e.currentTarget.dataset.fuwu;
    if(ifqianyue == 1)
    {
      wx.showToast({
        title: '签约中，请等待审核',
      })
    }else if(ifqianyue == 4 || ifqianyue == 3)
    {
      wx.showToast({
        title: '请重新签约',
      })
    }else if(fuwu == false)
    {
      wx.showModal({
        title: '提示',
        content:"请先购买服务包",
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/huanzhe/pages/private_services/private_services?zid='+zid,
            })
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/chat_list/chat_list?zid=' + zid+'&openid='+wx.getStorageSync('openid')+'&role=0&title='+that.data.z_name
      })
    }
  },
  // 在线问诊弹框
  showConsultation_btn: function (e) {
    if (this.data.docinfo.gzstype == 0) {
      wx.showModal({
        title: '提示',
        content: "该医生休息中，暂不支持问诊"
      })
    } else {
      this.setData({
        consultation_state: true
      })
    }

  },
  topingjia: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/pingjia/pingjia?zid=' + this.data.zid,
    })
  },
  //在线问诊选择
  consultation_btn: function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(e);
    var that = this;
    this.setData({
      consultation_index: index,
      link_url: e.currentTarget.dataset.url,
      ptmoney: e.currentTarget.dataset.ptmoney,
      hymoney: e.currentTarget.dataset.hymoney,
      titlme: e.currentTarget.dataset.titlme,
      time_leng: e.currentTarget.dataset.time_leng,
      ptzhuiw: e.currentTarget.dataset.ptzhuiw,
      hyzhuiw: e.currentTarget.dataset.hyzhuiw,
      key_words: e.currentTarget.dataset.key_words,
      ftitle: e.currentTarget.dataset.ftitle,
      buyreading: e.currentTarget.dataset.buyreading,
    })
    console.log(e)
    const query = wx.createSelectorQuery()
    query.select('#the_' + index).boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function (res) {
      that.setData({
        consultation_left: res[0].width / 2 + res[0].left - 15
      })
      res[0].top // #the-id节点的上边界坐标
      res[1].scrollTop // 显示区域的竖直滚动位置
    })

  },
  close_zhe: function (e) {
    this.setData({
      consultation_state: false
    })
  },

  showText: function () {
    this.setData({
      show_text: !this.data.show_text
    })
  },

  big_img: function (e) {
    var img_url = e.currentTarget.dataset.url;
    wx.previewImage({
      urls: [img_url],
    })
  },
  shareChose: function (e) {
    this.setData({
      shareState: true
    })
  },
  sharefri: function (e) {
    var that = this
    var docinfo = that.data.docinfo
    var zid = that.data.zid
    //生成医生二维码
    app.util.request({
      'url': 'entry/wxapp/index.iftuoke',
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        if (!res.data) {
          //我不是推客
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.docgenerate',
            data: {
              zid: zid
            },
            success: function (res) {
              console.log(res)
              that.setData({
                shareState: true,
                image_share: res.data
              })
              wx.previewImage({
                urls: [res.data],
              })
            }
          })
        } else {
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.tuikehaibao',
            data: {
              zid: zid,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              console.log(res)
              that.setData({
                shareState: true,
                image_share: res.data
              })
              wx.previewImage({
                urls: [res.data],
              })
            }
          })
        }
      }
    })


  },
  closeShare: function (e) {
    this.setData({
      shareState: false
    })
  },
  //向医生问诊   0 图文问诊   1 视频问诊
  askdoctor(e) {
    var that = this;
    let inquiry = e.currentTarget.dataset.num;
    var zid = this.data.zid
    var url = e.currentTarget.dataset.url
    var money = e.currentTarget.dataset.money
    var time_leng = e.currentTarget.dataset.time_leng
    var addnum = parseInt(e.currentTarget.dataset.ptzhuiw)
    var privateNum = this.data.privateNum
    var key_words = e.currentTarget.dataset.key_words;
    var openid = wx.getStorageSync('openid');
    if(openid == '')
    {
      wx.showModal({
        title: '提示',
        content:"请先登录",
        success:function(con)
        {
          if(con.confirm)
          {
              wx.navigateTo({
                url: '/hyb_yl/sgin/sgin',
              })
          }
        }
      })
    }else if(that.data.userfamily.length==0){
      wx.showModal({
        title: '提示',
        content:"请先添加患者信息",
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?type=1&gren=1',
            })
          }
        }
      })
    }else if (key_words == 'shoushukuaiyue') {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?key_words=' + key_words + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum + '&ifzy=1',
      })
    } else if (key_words == 'tijianjiedu') {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?key_words=' + key_words + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum + '&ifzy=1',
      })
    } else if (key_words == 'shuhoukangfu') {
      app.util.request({
        'url': "entry/wxapp/green.check_isbuy",
        data: {
          openid: wx.getStorageSync('openid'),
          zid: zid,
        },
        success: function (res) {
          var data = res.data;
          if (data.code == '0') {
            wx.showModal({
              title: '提示',
              content: data.message,
              showCancel: false,
              success: function (con) {
                if (con.confirm) {
                  wx.navigateTo({
                    url: '/hyb_yl/krecovery/pages/choose_operation/choose_operation?zid=' + zid + '&z_name=' + that.data.docinfo.z_name + '&agentname=' + that.data.docinfo.agentname + '&hid=' + that.data.docinfo.hid + '&keshi=' + that.data.docinfo.parentid + '&ks_title=' + that.data.docinfo.ctname,
                  })
                }
              }
            })

          } else if (data.code == '1' || data.code == '2') {
            wx.showModal({
              title: '提示',
              content: data.message,
              showCancel: false,
              success: function (con) {
                if (con.confirm) {
                  that.setData({
                    allserve: false
                  })
                }
              }
            })

          } else if (data.code == '3') {
            wx.showModal({
              title: '提示',
              content: data.message,
              showCancel: false,
              success: function (con) {
                if (con.confirm) {
                  wx.navigateTo({
                    url: '/hyb_yl/krecovery/pages/choose_operation/choose_operation?zid=' + zid + '&z_name=' + that.data.docinfo.z_name + '&agentname=' + that.data.docinfo.agentname + '&hid=' + that.data.docinfo.hid + '&keshi=' + that.data.docinfo.parentid + '&ks_title=' + that.data.docinfo.ctname,
                  })
                }
              }
            })
          } else if (data.code == '4') {
            wx.showModal({
              title: '提示',
              content: data.message,
              showCancel: false,
              success: function (con) {
                if (con.confirm) {
                  wx.navigateTo({
                    url: '/hyb_yl/krecovery/pages/order_list/order_list',
                  })
                }
              }
            })

          }
        }
      })

    } else {
      wx.navigateTo({
        url: url + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum + '&ifzy=1' + '&name=' + e.currentTarget.dataset.name,
      })
    }

    // switch (inquiry) {
    //   case '0':
    //     wx.navigateTo({
    //       url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?inquiry=' + inquiry + '&zid=' + zid,
    //     })
    //     break;
    //   case '1':
    //     wx.navigateTo({
    //       url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=' + inquiry + '&zid=' + zid,
    //     })
    //     break;
    //   case '2':
    //     wx.navigateTo({
    //       url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=' + inquiry + '&zid=' + zid,
    //     })
    //     break;
    //   case '3':
    //     wx.navigateTo({
    //       url: '../chufangmes/chufangmes?inquiry=' + inquiry + '&zid=' + zid,
    //     })
    //     break;
    //   case '4':
    //     wx.navigateTo({
    //       url: '/hyb_yl/backstageServices/pages/kaiyao/kaiyao?inquiry=' + inquiry + '&zid=' + zid,
    //     })
    //     break;
    //   default:
    //     console.log(inquiry)
    // }

  },
  //开通年卡
  yearcard(e) {
    var id = e.currentTarget.dataset.id;
    var zid = this.data.zid;
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yearcard/yearcard?id=' + id + '&zid=' + zid,
    })
  },
  // 展开收起主治擅长
  fold: function () {
    this.setData({
      adepd: !this.data.adepd
    })
  },
  extract: function () {
    var username = this.data.username;
    var username = username.substr(0, 1) + '***';
    this.setData({
      username: username
    })
    console.log(this.data.username)
  },
  // 关注
  collect: function () {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.changelove',
      data: {
        zid: that.data.zid,
        openid: wx.getStorageSync('openid'),
        cerated_type: 0
      },
      success: function (res) {
        console.log(res)
        //提醒
        app.util.request({
          'url': 'entry/wxapp/user.memberopentx',
          data: {
            near: '用户关注提醒',
            openid: wx.getStorageSync('openid'),
            zid: that.data.zid
          },
          success: function (res) {
            console.log(res)
          }
        })
      }
    })
    this.setData({
      collect: !this.data.collect
    })
    if (this.data.collect == true) {
      wx.showToast({
        title: '关注成功',
        icon: 'none',
      })
    } else {

      wx.showToast({
        title: '取消关注成功',
        icon: 'none',
      })
    }
  },
  //全部服务弹框
  two_even: function (e) {
    var server = this.data.server;
    // var mytkid = app.globalData.mytkid
    // var tkid = app.globalData.tkid

    if (this.data.inquiry == 5) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=5',
      })
      return false
    }
    if (this.data.inquiry == 6) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=6',
      })
      return false
    } else if (server == 'shoushukuaiyue' || server == 'yuanchengguahao') {
      var menu = this.data.menu;
      var server = this.data.server;

      var money = '';
      var time_leng = '';
      var monptzhuiwey = '';
      var hyzhuiw = '';
      var ptzhuiw = '';
      var docinfo = this.data.docinfo;

      for (var i = 0; i < menu.length; i++) {
        if (menu[i].key_words == server) {
          if (docinfo.vip) {
            money = menu[i].hymoney;
          } else {
            money = menu[i].ptmoney;
          }

          time_leng = menu[i].time_leng;
          ptzhuiw = menu[i].ptzhuiw;
          hyzhuiw = menu[i].hyzhuiw;
        }
      }

      var inquiry = 0;
      var zid = this.data.zid
      if (docinfo.vip) {
        var addnum = parseInt(hyzhuiw)
      } else {
        var addnum = parseInt(ptzhuiw)
      }
      var privateNum = this.data.privateNum
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?key_words=' + server + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum,
      })
      return false
    } else if (this.data.server == 'tijianjiedu') {
      var menu = this.data.menu;
      var server = this.data.server;
      var money = '';
      var time_leng = '';
      var monptzhuiwey = '';
      var hyzhuiw = '';
      var ptzhuiw = '';
      var docinfo = this.data.docinfo;
      for (var i = 0; i < menu.length; i++) {
        if (menu[i].key_words == server) {
          if (docinfo.vip) {
            money = menu[i].hymoney;
          } else {
            money = menu[i].ptmoney;
          }
          time_leng = menu[i].time_leng;
          ptzhuiw = menu[i].ptzhuiw;
          hyzhuiw = menu[i].hyzhuiw;
        }
      }
      var inquiry = 0;
      var zid = this.data.zid
      if (docinfo.vip) {
        var addnum = parseInt(hyzhuiw)
      } else {
        var addnum = parseInt(ptzhuiw)
      }
      var privateNum = this.data.privateNum
      if (this.data.tid) {
        wx.navigateTo({
          url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?key_words=' + server + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum + '&tjorder=' + this.data.tid,
        })
        return false
      }
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?key_words=' + server + '&money=' + money + '&zid=' + zid + '&time_leng=' + time_leng + '&addnum=' + addnum + '&privateNum=' + privateNum,
      })
      return false

    } else {
      this.setData({
        allserve: true,
      })
    }
  },
  // g关闭服务弹框
  closeallserve() {
    this.setData({
      allserve: false,
    })
  },
  // 选择擅长
  questionclick(e) {
    var that = this
    var biaoqian = e.currentTarget.dataset.biaoqian
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getgkquestion',
      data: {
        zid: zid,
        biaoqian: biaoqian
      },
      success: function (res) {
        console.log(res)
        that.setData({
          listqs: res.data
        })
      }
    })
    this.setData({
      questiontabs: e.currentTarget.dataset.dex
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.channel = "";
    var openid = wx.getStorageSync('openid');
    if (openid == '') {
      wx.showModal({
        cancelColor: '提示',
        content: "请先登录",
        success: function (con) {
          if (con.confirm) {
            wx.navigateTo({
              url: '/hyb_yl/sgin/sgin',
            })
          } else {
            wx.switchTab({
              url: '/hyb_yl/tabBar/index/index',
            })
          }

        }
      })
    }
    this.uid = Utils.getUid();
    //查询是否是拓客专员
    app.util.request({
      'url': 'entry/wxapp/index.iftuoke',
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        if (res.data == 0 && res.data !== false) {
          app.globalData.mytkid = ''
        } else {
          if (res.data.tkid == 0) {
            app.globalData.ziji = 1 //如果自己是1
          } else {
            app.globalData.ziji = 0 //如果不是自己是0
          }
        }

      },
    })
    if (options.tid) {
      var tid = options.tid
      this.setData({
        tid: tid
      })
    }
    this.lock = false;
    let userInfo = wx.getStorageSync("userInfo");
    var money = options.money
    //查询是否签约

    if (userInfo) {
      this.setData({
        hasUserInfo: true,
        userInfo: userInfo
      });
    }
    var typs = options.typs;
    if (typs != undefined) {
      this.setData({
        typs: typs
      })
    }
    var openid = wx.getStorageSync('openid')
    if (openid) {
      this.setData({
        isAuthor: true
      })
    } else {
      this.setData({
        isAuthor: false
      })
    }
    var that = this
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      bgc: bgc
    })
    app.util.request({
      'url': 'entry/wxapp/index.base',
      success: function (res) {
        that.setData({
          show_title: res.data.show_title,
          state: res.data.state
        })
      }
    })

    if (decodeURIComponent(options.scene) !== 'undefined') {

      var doc = decodeURIComponent(options.scene);
      var docArr = doc.split('&')
      var arr = []
      for (var i = 0; i < docArr.length; i++) {
        arr.push(docArr[i].split('='))
      }
      var numArr = []
      for (var i = 0; i < arr.length; i++) {
        numArr.push(arr[i][1])
      }
      var zid = numArr[0];
      var tkid = numArr[1];
      var mytkid = app.globalData.mytkid;
      console.log(tkid)
      //查询是否是拓客专员
      app.util.request({
        'url': 'entry/wxapp/index.iftuoke',
        data: {
          openid: wx.getStorageSync('openid')
        },
        success: function (res) {
          console.log(res)
          var id = res.data.id
          if (id == tkid) {
            app.globalData.tkid = 0
          } else {
            app.globalData.tkid = tkid
          }
        },
      })
      app.globalData.mytkid = mytkid
      //查询我上级的上级
      app.util.request({
        url: 'entry/wxapp/tuike.myshangji',
        data: {
          id: tkid
        },
        success: function (res) {
          console.log(res)
          if (res.data == 0 && res.data !== false) {
            app.globalData.mytkid = '' //二级分销商
            app.globalData.ziji = 1 //如果存在上级是1
          } else {
            app.globalData.mytkid = res.data //上级id
            app.globalData.ziji = 0 //如果不存在是0
          }
        }
      })
      //查询用户信息
      app.util.request({
        'url': 'entry/wxapp/tuike.userinfodata',
        data: {
          tkid: tkid,
        },
        success: function (res) {
          console.log(res)
          var username = res.data.username
          //增加分享次数
          app.util.request({
            'url': 'entry/wxapp/index.updatetuike',
            data: {
              tkid: tkid,
              mytkid: mytkid,
              type: 4,
              openid: wx.getStorageSync('openid'),
              content: '通过' + username + '分享进入',
              zid: zid
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })

      that.setData({
        tkid: tkid,

      })
    } else {
      var zid = options.zid
    }
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.checkcollect2',
      data: {
        openid: wx.getStorageSync('openid'),
        goods_id: zid
      },
      success: function (res) {
        console.log(res)
        if (res.data == false) {
          that.setData({
            ifqianyue: '0'
          })
        }
        if (res.data != false && res.data.ifqianyue) {
          that.setData({
            ifqianyue: res.data.ifqianyue
          })
        }
        if (res.data.ifqianyue == 2) {
          that.setData({
            text: "已签约"
          })
        } else if (res.data.ifqianyue == 1) {
          that.setData({
            text: "签约中"
          })
        } else if (res.data.ifqianyue == 3) {
          that.setData({
            text: "已解约"
          })
        } else if (res.data.ifqianyue == 4) {
          that.setData({
            text: "已取消"
          })
        } else if (res.data.ifqianyue == 5) {
          that.setData({
            text: "已拒绝"
          })
        }

      }
    })

    var key = options.server
    var msg = options.msg
    var name = options.name
    that.setData({
      bgc: bgc,
      inquiry: options.inquiry,
      bgc: bgc,
      zid: zid,
      key: key,
      msg: msg,
      btn: key,
      name: name,
      money: money,
      server: options.server
    })

    // 获取到屏幕的宽高等信息
    var maskWidth;
    wx: wx.getSystemInfo({
      success: function (res) {
        console.log(res)
        maskWidth = Math.round(res.screenWidth * 0.8)
        that.setData({
          windowWidth: res.windowWidth,
          windowHeight: res.windowHeight,
          maskWidth: maskWidth,
          maskHeight: Math.round(maskWidth * 1920 / 1080),
        })
      }
    })
    app.util.request({
      'url':"entry/wxapp/user.alluserfamily",
      data:{
        openid:wx.getStorageSync('openid')
      },
      success:function(res)
      {
        that.setData({
          userfamily:res.data
        })
      }
    })
  },

  likesClick(e) {
    console.log(e)
    var openid = wx.getStorageSync('openid')
    if (openid) {
      //登录环信
      var me = this
      me.setData({
        isAuthor: true
      })
    } else {
      me.setData({
        isAuthor: false
      })
    }
  },
  bindUsername: function (e) {
    this.setData({
      name: e.detail.value
    });
  },

  bindPassword: function (e) {
    this.setData({
      psd: e.detail.value
    });
  },
  onFocusPsd: function () {
    this.setData({
      psdFocus: 'psdFocus'
    })
  },
  onBlurPsd: function () {
    this.setData({
      psdFocus: ''
    })
  },
  onFocusName: function () {
    this.setData({
      nameFocus: 'nameFocus'
    })
  },
  onBlurName: function () {
    this.setData({
      nameFocus: ''
    })
  },
  login: function (e) {
    runAnimation = !runAnimation
    wx.setStorage({
      key: "myUsername",
      data: wx.getStorageSync('myUsername')
    });
    getApp().conn.open({
      apiUrl: WebIM.config.apiURL,
      user: wx.getStorageSync('myUsername'),
      pwd: '123',
      grant_type: this.data.grant_type,
      appKey: WebIM.config.appkey
    });
    console.log(wx.getStorageSync('myUsername'))
    var that = this
    var btn = that.data.btn
    console.log(btn)
    var randnum = that.data.randnum
    var docopenid = that.data.docopenid
    var useropenid = wx.getStorageSync('openid')
    if (docopenid == useropenid) {
      wx.showToast({
        title: '自己不能咨询自己',
        icon: 'none'
      })
      return false;
    }
    if (btn == 'dianhuawenzhen') {
      that.dianhuawenzhen(randnum)
    }
    if (btn == 'tuwenwenzhen') {
      that.tuwenwenzhen(randnum)
    }
    if (btn == 'sirenyisheng') {
      that.sirenyisheng(randnum)
    }
    if (btn == 'yuanchengwenzhen') {
      that.yuanchengwenzhen(randnum)
    }
    if (btn == 'zhuanjiatuandui') {
      that.zhuanjiatuandui(randnum)
    }
    if (btn == 'shoushukuaiyue') {
      that.shoushukuaiyue(randnum)
    }
    if (btn == 'tijianjiedu') {
      that.tijianjiedu(randnum)
    }
  },


  onGotUserInfo: function (e) {
    var that = this
    let userInfo = e.detail.userInfo || {};
    // store data for next launch use
    wx.setStorage({
      key: 'userInfo',
      data: userInfo,
    })
    var key = that.data.key
    if (key == 'tuwenwenzhen') {
      var my = wx.getStorageSync("myUsername");
      console.log(my)
      var nameList = {
        myName: my,
        your: 'jinjin123456789'
      };
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/chatroom/chatroom?username=' + JSON.stringify(nameList),
      })
    } else {
      this.onJoin(userInfo);
    }
  },

  checkJoinLock: function () {
    return !(this.lock || false);
  },

  lockJoin: function () {
    this.lock = true;
  },

  unlockJoin: function () {
    this.lock = false;
  },

  onJoin: function (userInfo) {
    userInfo = userInfo || {};
    let value = this.channel || "123";

    let uid = this.uid;
    if (!value) {
      wx.showToast({
        title: '请提供一个有效的房间名',
        icon: 'none',
        duration: 2000
      })
    } else {
      if (this.checkJoinLock()) {
        this.lockJoin();
        let role = "audience";
        role = "broadcaster";
        wx.navigateTo({
          url: `../meeting/meeting?channel=${value}&uid=${uid}&role=${role}`
        });
      }
    }
  },
  onInputChannel: function (e) {
    let value = e.detail.value;
    this.channel = value;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('1')
    this.extract()
    //获取时间
    // 调用函数时，传入new Date()参数，返回值是日期和时间
    let time = Utils.formatTime(new Date());
    let day = parseFloat(time.slice(8, 10));
    let ctime = time.slice(5, 7) + '月' + day + '日';
    this.setData({
      pop_time1: ctime,
      consultation_index: 0,
    })
    for (var i = 0; i < 5; i++) {
      let times = time.slice(5, 7) + '月' + day + '日';
      day++;

      this.data.ctab_scroll.push(times)
      this.setData({
        ctab_scroll: this.data.ctab_scroll
      })
      // console.log(this.data.ctab_scroll) 
    }
    var me = this
    var openid = wx.getStorageSync('openid')
    console.log(openid)
    if (openid) {
      me.setData({
        bigMask: true
      })
      app.util.request({
        'url': "entry/wxapp/user.is_vip",
        data: {
          openid: wx.getStorageSync('openid')
        },
        success: function (res) {
          me.setData({
            is_vip: res.data.is_vip
          })
          me.getserver()
          console.log(me.data.is_vip)
        }
      })
    } else {
      me.setData({
        bigMask: false
      })
    }
    me.getDocinfo()
    me.getguanzhu()
    me.getgkpingjia()
    me.getdocpingjia()
    me.extract()
    
  },
  onShareAppMessage(){
    return{
      path:'hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid='+this.data.zid
    }
  },
  // 首页
  navicate() {
    var that = this
    wx.reLaunch({
      url: '/hyb_yl/tabBar/index/index',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('2')
    this.setData({
      consultation_state: false,
      consultation_left: 100
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log('2')
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  guahao: function () {
    var that = this;
    if (that.data.docinfo.gzstype == 0) {
      wx.showModal({
        title: '提示',
        content: "该医生休息中，暂不支持问诊"
      })
    } else {
      app.util.request({
        'url': "entry/wxapp/green.check_isbuy",
        data: {
          openid: wx.getStorageSync('openid'),
          zid: that.data.zid
        },
        success: function (res) {
          if (res.data.code == 1 || res.data.code == 2) {
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/doctor_detail/doctor_detail?inquiry=1&zid=' + this.data.zid + '&server=yuanchengguahao&money=0',
            })
          } else {
            var menu = that.data.menu;
            var server = 'yuanchengguahao';

            var money = '';
            var time_leng = '';
            var monptzhuiwey = '';
            var hyzhuiw = '';
            var ptzhuiw = '';
            var docinfo = that.data.docinfo;

            for (var i = 0; i < menu.length; i++) {
              if (menu[i].key_words == server) {
                if (docinfo.vip) {
                  money = menu[i].hymoney;
                } else {
                  money = menu[i].ptmoney;
                }

                time_leng = menu[i].time_leng;
                ptzhuiw = menu[i].ptzhuiw;
                hyzhuiw = menu[i].hyzhuiw;
              }
            }
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/doctor_detail/doctor_detail?inquiry=1&zid=' + that.data.zid + '&server=yuanchengguahao&money=' + money,
            })
          }
        }
      })

    }
  },
  getDocinfo(e) {
    var that = this
    var zid = that.data.zid
    var key = that.data.btn
    console.log(key)
    if (key == 'undefined') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.docinfo',
        data: {
          zid: zid,
          key: key,
          openid: wx.getStorageSync('openid')
        },
        success: function (res) {
          console.log(res)
          wx.setNavigationBarTitle({
            title: res.data.z_name
          })
          that.setData({
            docopenid: res.data.openid,
            docinfo: res.data,
            z_name: res.data.z_name,
            randnum: res.data.randnum,
            isLoading: !1,
            fuwu:res.data.fuwu,
          })
          console.log(res.data.video)
          if (res.data.video != '') {
            that.setData({
              video: true
            })
          }

        }
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getdocinfo',
        data: {
          zid: zid,
          openid: wx.getStorageSync('openid')
        },
        success: function (res) {
          console.log(res)
          wx.setNavigationBarTitle({
            title: res.data.z_name
          })
          var biaoqian = res.data.authority[0].bq
          console.log(biaoqian)
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getgkquestion',
            data: {
              zid: zid,
              biaoqian: biaoqian
            },
            success: function (res) {
              console.log(res)
              that.setData({
                listqs: res.data,
                isLoading: !1,
              })
            }
          })
          that.setData({
            docopenid: res.data.openid,
            docinfo: res.data,
            z_name: res.data.z_name,
            randnum: res.data.randnum,
            privateNum: res.data.privateNum,
            authority: res.data.authority,
            fuwu:res.data.fuwu,
          })
          if (res.data.video != '') {
            that.setData({
              video: true
            })
          }

        }
      })
    }

  },
  answer_detail: function (e) {
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title;
    var typs = e.currentTarget.dataset.typs;
    var state = e.currentTarget.dataset.state
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/publicProblemsInfor/publicProblemsInfor?id=' + id + '&title=' + title + '&typs=' + typs + '&state=' + state,
    })
  },
  dianhuawenzhen(randnum) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/telserev/index?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  tuwenwenzhen(randnum) {
    var that = this
    var name = that.data.name
    var zid = that.data.zid
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiatiwen/zhuanjiatiwen?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  sirenyisheng(randnum) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/perdoc/index?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  yuanchengwenzhen(randnum) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/longsevers/index?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  tijianjiedu(randnum) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  zhuanjiatuandui(randnum) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    wx.navigateTo({
      url: '/hyb_yl/doctor/pages/familydoctor/servercenter/servercenter?zid=' + zid + '&keywords=' + keywords + '&name=' + name + '&randnum=' + randnum,
    })
  },
  shoushukuaiyue(e) {
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.btn
    var money = that.data.money
    var z_name = that.data.z_name
    var hospital = that.data.hospital
    wx.navigateTo({
      url: '/hyb_yl/userCommunicate/pages/preindex/index/index?zid=' + zid + '&key=' + keywords + '&name=' + name + '&money=' + money + '&z_name=' + z_name + '&hospital=' + hospital + '&msg=立即预约',
    })
  },
  //是否关注
  getguanzhu() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.ifguanzhu',
      data: {
        zid: that.data.zid,
        openid: wx.getStorageSync('openid'),
        cerated_type: 0
      },
      success(res) {
        console.log(res)
        if (res.data == 1) {
          that.setData({
            collect: !that.data.collect
          })
        } else {
          that.setData({
            collect: that.data.collect
          })
        }
      }
    })
  },
  //查询医生评价
  getdocpingjia() {
    var that = this
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.pjlist',
      data: {
        zid: zid
      },
      success: function (res) {
        var list = res.data
        for (var i = 0; i < list.length; i++) {
          list[i].names = list[i].names.substr(0, 1) + '***';
        }
        that.setData({
          list: list
        })
        console.log(res)
      }
    })
  },
  toallpingjia: function () {
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/estimate/estimate?zid=' + this.data.zid,
    })
  },
  //查询所有服务
  getserver() {
    var that = this
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.server',
      data: {
        zid: zid,
      },
      success: function (res) {
        var list = res.data
        console.log(res)
        that.setData({
          menu: list,
          link_url: list[0].url + '&zid=' + zid,
          ptmoney: list[0].ptmoney,
          hymoney: list[0].hymoney,
          titlme: list[0].titlme,
          time_leng: list[0].time_leng,
          ptzhuiw: list[0].ptzhuiw,
          hyzhuiw: list[0].hyzhuiw,
          key_words: list[0].key_words,
          ftitle: list[0].info.ftitle,
          buyreading: list[0].info.buyreading,
        })
      }
    })
  },
  //查询公开问题
  // getgkwenti() {
  //   var that = this
  //   var zid = that.data.zid
  //   app.util.request({
  //     'url': 'entry/wxapp/zhuanjia.getgkquestion',
  //     data: {
  //       zid: zid
  //     },
  //     success: function (res) {
  //       console.log(res)
  //       that.setData({
  //         listqs: res.data
  //       })
  //     }
  //   })
  // },
  //查询公开评价
  getgkpingjia() {
    var that = this
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getgkpingjia',
      data: {
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          listpj: res.data
        })
      }
    })
  },
  //我再想想
  abolishBtn: function () {
    this.setData({
      modelBoo: false,
      ifqianyue: 0,
      text: '签约医生'
    });
  },
  vip: function () {
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/vip/vip',
    })
  },
  //签约
  qianyue(e) {
    var that = this
    if (e.currentTarget.dataset.ifqianyue == 0) {
     
      wx.navigateTo({
        url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+that.data.zid,
      })

    }
    if (e.currentTarget.dataset.ifqianyue == 1) {
      //取消签约
      wx.showModal({
        title: '签约中,签约后才可使用专家服务',
        content: '是否取消申请',
        success: function (res) {
          if (res.confirm) {
            that.setData({
              ifqianyue: 4,
              text: '已取消'
            })
            that.signedBtn()
          }
        }
      })
    }
    if (e.currentTarget.dataset.ifqianyue == 4 || e.currentTarget.dataset.ifqianyue == 3 || e.currentTarget.dataset.ifqianyue == 5) {
      //取消签约
      wx.navigateTo({
        url: '/hyb_yl/huanzhe/pages/patient_report/patient_report?zid='+that.data.zid,
      })
    }
    if (e.currentTarget.dataset.ifqianyue == 2) {
      //取消签约
      wx.showModal({
        content: '是否解除签约',
        success: function (res) {
          if (res.confirm) {
            that.setData({
              ifqianyue: 3,
              text: '已解约'
            })
            that.signedBtn()
          }
        }
      })
    }
  },
  // qianyue(e) {
  //   var that = this
  //   if (e.currentTarget.dataset.ifqianyue == 0) {
  //     this.setData({
  //       modelBoo: true,
  //       ifqianyue: 1,
  //       text: "签约中"
  //     })
  //   }
  //   if (e.currentTarget.dataset.ifqianyue == 1) {
  //     //取消签约
  //     wx.showModal({
  //       title: '签约中,签约后才可使用专家服务',
  //       content: '是否取消申请',
  //       success: function (res) {
  //         if (res.confirm) {
  //           that.setData({
  //             ifqianyue: 4,
  //             text: '已取消'
  //           })
  //           that.signedBtn()
  //         }
  //       }
  //     })
  //   }
  //   if (e.currentTarget.dataset.ifqianyue == 4 || e.currentTarget.dataset.ifqianyue == 3 || e.currentTarget.dataset.ifqianyue == 5) {
  //     //取消签约
  //     wx.showModal({
  //       content: '是否重新申请',
  //       success: function (res) {
  //         if (res.confirm) {
  //           that.setData({
  //             ifqianyue: 1,
  //             text: '签约中'
  //           })
  //           that.signedBtn()
  //         }
  //       }
  //     })
  //   }
  //   if (e.currentTarget.dataset.ifqianyue == 2) {
  //     //取消签约
  //     wx.showModal({
  //       content: '是否解除签约',
  //       success: function (res) {
  //         if (res.confirm) {
  //           that.setData({
  //             ifqianyue: 3,
  //             text: '已解约'
  //           })
  //           that.signedBtn()
  //         }
  //       }
  //     })
  //   }
  // },
  checkboxChange: function (e) {
    console.log(e)
    var that = this
    if (e.detail.value[0] == undefined) {
      var change = 0
    } else {
      var change = e.detail.value[0]
    }
    that.setData({
      change: change
    })
  },


  // 点击签约
  signedBtn: function (e) {
    var that = this;
    var zid = that.data.zid
    var openid = wx.getStorageSync('openid');
    var change = that.data.change
    var ifqianyue = that.data.ifqianyue
    var text = that.data.text
    //查询第一个j_id
    console.log(e)
    var j_id = that.data.j_id

    app.util.request({
      'url': 'entry/wxapp/zhuanjia.checkcollect',
      data: {
        openid: openid,
        zid: zid,
        cerated_type: 7, //签约专家
      },
      success: function (res) {
        console.log(res)
        app.util.request({
          'url': 'entry/wxapp/zhuanjia.savecollectup',
          data: {
            openid: openid,
            goods_id: zid,
            cerated_type: 7,
            ifqianyue: ifqianyue,
            change: change,
          },
          success: function (res) {
            console.log(res);
            wx.showToast({
              title: '操作成功',
              icon: 'none',
              duration: 1500,
              success: function () {
                //签约提醒
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.remind',
                  data: {
                    openid: openid,
                    zid: zid,
                    j_id: j_id
                  },
                  success: function (res) {
                    console.log(res)
                  }
                })
              }
            })
            that.setData({
              modelBoo: false,
              text: text,
              ifqianyue: ifqianyue,
              stype: res.data
            })
          },

        })
      },
    })
  },
  mytouchstart(e) {
    console.log(e)
    var that = this
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.checkcollect2',
      data: {
        openid: wx.getStorageSync('openid'),
        goods_id: zid
      },
      success: function (res) {
        console.log(res)
        if (res.data.ifqianyue) {
          that.setData({
            ifqianyue: res.data.ifqianyue
          })
        }
        if (res.data.ifqianyue == 2) {
          that.setData({
            text: "已签约"
          })
        } else if (res.data.ifqianyue == 1) {
          that.setData({
            text: "签约中"
          })
        } else if (res.data.ifqianyue == 3) {
          that.setData({
            text: "已解约"
          })
        } else if (res.data.ifqianyue == 4) {
          that.setData({
            text: "已取消"
          })
        } else if (res.data.ifqianyue == 5) {
          that.setData({
            text: "已拒绝"
          })
        }

      }
    })
  }
})